Repository navigation
fix: keep subclasses in the remaining content part from_dict methods - #13605
Open
simin-yuan wants to merge 2 commits into
Open
simin-yuan wants to merge 2 commits into
simin-yuan wants to merge 2 commits into
Conversation
simin-yuan
requested review from
davidsbatista
and removed request for
a team
November 6, 2026 17:28
Contributor
|
@simin-yuan is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
ToolCall, ToolCallResult, ReasoningContent, ToolCallDelta and ComponentInfo hardcoded their own class in from_dict, so a subclass lost its extra fields on a to_dict()/from_dict() round trip. deepset-ai#13180 and deepset-ai#13536 fixed the same bug for ByteStream and for TextContent/FileContent/ImageContent; this completes the set in haystack/dataclasses. Signed-off-by: Simin Yuan <281164480+simin-yuan@users.noreply.github.com>
simin-yuan
force-pushed
the
fix/content-part-from-dict-subclasses
branch
from
November 6, 2026 17:31
03ebf83 to
c20aac5
Compare
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||
Contributor
Author
|
Closing this as I'm not able to follow up on it. Thanks for the time. |
…om-dict-subclasses
Contributor
Author
|
Merged current main into the branch; tests pass. The issue is still present on main (ToolCall.from_dict still returns the base class for subclasses). Happy to adjust. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issues
from_dicts.Same bug, the classes that PR left out; fix: preserve ByteStream subclasses during deserialization #13180 (
ByteStream, by @JimmyWang0417) fixed the same thing earlier.No open issue tracks the remaining classes.
Proposed Changes:
ToolCall,ToolCallResultandReasoningContentinhaystack.dataclasses.chat_message, andToolCallDeltaandComponentInfoinhaystack.dataclasses.streaming_chunk, are content parts whosefrom_dicthardcoded its own class(
return ToolCall(**data)). Called on a subclass, it returned a base-class instance, so any extra field the subclasscarries was silently dropped after a
to_dict()/from_dict()round trip.They now instantiate
cls(**data)and are annotated-> Self, the same shapeTextContent,FileContentandImageContentgot in #13536, andByteStreamgot in #13180. Base-class behaviour is unchanged: the content-partregistry in
_deserialize_content_partstill looks up the base classes.How did you test it?
One regression test per class, each defining a trivial
@dataclasssubclass and assertingtype(Sub.from_dict(Sub(...).to_dict())) is Sub.5 failed, 1 passed(the pass is the existingtest_text_content_subclass_from_dictfrom fix: keep subclasses in content part from_dict #13536).203 passedfortest/dataclasses/test_chat_message.py test/dataclasses/test_streaming_chunk.py.pytest test/dataclasses:370 passed, 2 failed. Both failures are pre-existing on this Windows machine andunrelated to this change:
test_from_file_path_guess_mime_type[spam.csv-...]reads the local CSV mime mapping, andtest_image_content_show_in_jupyterneedsIPython, which isn't installed here.Notes for the reviewer
ToolCallResult.from_dictnow buildscls(...), but its nestedoriginis still deserialized as the baseToolCall, because the serialized payload carries no type information for that field. Adding a type key there is alarger change; happy to do it separately if you want it.
ChatMessage.from_dictandStreamingChunk.from_dictare untouched: they hand-build their fields and already usecls, so they never had this problem.Checklist
fix:.AI assistance: this patch and its tests were drafted with an AI assistant under my direction. I reviewed the diff and ran the relevant tests locally — without the change the new cases fail (5 failed, 1 passed); with it the file is green (203 passed).
This PR was prepared with an AI assistant (Hermes); I reviewed the diff and ran the tests.